package com.woniu.common.utils;

import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * packageName com.fresh.utils
 *
 * @author zxyang3636
 * @version JDK 8
 * @className GetCurrentUserId
 * @date 2024/7/3
 * @description TODO 获取当前app userId
 */
public class GetCurrentUserId {
    public static String getUserId() throws Exception {
        HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
        String jwt = request.getHeader("token");
        Map userInfo = (Map) JWTUtil.getUserInfo(jwt).get("zyManage");
        String userId = (String) userInfo.get("id");
        return userId;
    }
}
